| Total Complexity | 4 | 
| Total Lines | 27 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | /* eslint-disable sort-keys */ | ||
| 8 | |||
| 9 | export class HasLogger { | ||
| 10 | public logger!: Logger; | ||
| 11 | |||
| 12 |     public createLogger(targets: LogTarget[], defaultMeta: Record<string, any>) { | ||
| 13 |         this.logger = winston.createLogger({ | ||
| 14 | level: 'info', | ||
| 15 | format: winston.format.json(), | ||
| 16 | defaultMeta, | ||
| 17 | transports: [], | ||
| 18 | }); | ||
| 19 | |||
| 20 |         if (targets.includes('file')) { | ||
| 21 |             new winston.transports.File({ filename: `${__dirname}/codeboost.log` }); | ||
| 22 | } | ||
| 23 | |||
| 24 |         //if (targets.includes('console')) { | ||
| 25 |         this.logger.add(new winston.transports.Console({ format: winston.format.simple() })); | ||
| 26 | //} | ||
| 27 | } | ||
| 28 | |||
| 29 |     public log(message: string, meta: any[] = []) { | ||
| 30 |         if (!this.logger || this.logger.transports.length === 0) { | ||
| 31 | return; | ||
| 32 | } | ||
| 33 | |||
| 34 |         this.logger.info(message, ...[merge.all([{ _ts: dayjs().toISOString() }, ...meta])]); | ||
| 35 | } | ||
| 37 |